<?php
class Sys_media_type_model extends CI_Model {

	public function __construct(){
		parent::__construct();
		$this->db = $this->load->database('default',true);
	}

	public function  query_media_types() {
		$sql ="select * from sys_media_type where  be_delete ='0' and  parent_id ='$parent_id' order by media_type_id asc";
		$query	=$this->db->query($sql);
		if ($query->num_rows()>0) {
			return $query->result_array();
		}
	}

	public function query_media_type_info($media_type_id){
		$sql ="select * from  sys_media_type where  be_delete ='0' and  media_type_id ='$media_type_id' limit 1";
		$query	=$this->db->query($sql);
		if ($query->num_rows()>0) {
			return $query->row_array();
		}
	}

	public function query_media_type_info_by_name($media_type_name){
		$sql ="select * from  sys_media_type where be_delete ='0' and  media_type_name ='$media_type_name' limit 1";
		$query	=$this->db->query($sql);
		if ($query->num_rows()>0) {
			return $query->row_array();
		}
	}
	public function insert_media_type($media_type){
		$media_type['be_delete']=0;
		$this->db->insert('sys_media_type',$media_type);
	}
	public function update_media_type($media_type,$media_type_id){
		$this->db->where('media_type_id',$media_type_id);
		$this->db->update('sys_media_type',$media_type);
	}

	public function set_delete_media_type($media_type_id){
		$sql ="update sys_media_type set be_delete ='1' where media_type_id='$media_type_id'";
		$this->db->query($sql);
	}

	public function query_media_type_list($start,$limit) {
		$sql ="select media_type_id,media_type_name from sys_media_type where be_delete ='0'  order by media_type_id asc limit $start,$limit";
		$query =$this->db->query($sql);
		if ($query) {
			return $query->result_array();
		}
	}

	public function query_media_type_num(){
		$sql ="select count(media_type_id) as num from sys_media_type  where be_delete ='0' ";
		$query =$this->db->query($sql);
		if ($query){
			$row =$query->row_array();
			return $row['num'];
		}
	}
	
	public function get_all_media_type(){
		$sql ="select media_type_id,media_type_name from sys_media_type where be_delete ='0' order by media_type_id asc";
		$query =$this->db->query($sql);
		if ($query) {
			return $query->result_array();
		}
	}
}
?>